<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2023/12/27
 * Time: 10:01
 */

namespace app\api\model;

class OrderCg extends Base
{
    /**
     * 查询用户草稿订单
     * @param $where
     * @param $field
     * @return array|bool|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function findOrderCg($where = [], $field = '*'){
        return self::where($where)->field($field)->find();
    }

    /**
     * 联查单条用户草稿订单
     * @param $where
     * @param $field
     * @return array|bool|\PDOStatement|string|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    static function findJoinOrderCg($where = [], $field = '*'){
        $data = self::join('up_area a1', 'order_sheng = a1.district_id', 'LEFT')
            ->join('up_area a2', 'order_shi = a2.district_id', 'LEFT')
            ->join('up_area a3', 'order_qu = a3.district_id', 'LEFT')
            ->where($where)
            ->field($field)
            ->find();
        if($data){
            $data = $data->toArray();
        }
        return $data;
    }

    /**
     * 更新草稿订单
     * @param $where
     * @param $update
     * @return OrderCg
     */
    static function updateOrderCg($where = [], $update = []){
        return self::where($where)->update($update);
    }

    /**
     * 插入草稿订单
     * @param $insert
     * @return int|string
     */
    static function insertOrderCg($insert = []){
        return self::insertGetId($insert);
    }

    /**
     * 删除草稿订单
     * @param $id
     * @return false|int
     */
    static function delOrderCg($where = []){
        return self::where($where)->delete();
    }
}